package com.hellpro.lolbox.moment.model;

import android.net.Uri;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.TextView;

import com.facebook.drawee.view.SimpleDraweeView;
import com.hellpro.lolbox.R;
import com.hellpro.lolbox.moment.bean.MomentContentBean;

import java.util.List;

import butterknife.BindView;
import butterknife.ButterKnife;

/**
 * 类描述:
 * 创建人:阿犇
 * 创建时间:2016/10/22
 * 备注:moment的Adapter
 */

public class MomentContentLvAdapter extends BaseAdapter {

    private List<MomentContentBean.DataBean> mList;

    public MomentContentLvAdapter() {
    }


    public void setData(List<MomentContentBean.DataBean> data) {
        this.mList=data;
        notifyDataSetChanged();
    }

    @Override
    public int getCount() {
        return mList != null ? mList.size() : 0;
    }

    @Override
    public Object getItem(int position) {
        return mList != null ? mList.get(position) : null;
    }

    @Override
    public long getItemId(int position) {
        return position;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {

        ViewHolder holder;
        if (convertView == null) {
            convertView = LayoutInflater.from(parent.getContext()).inflate(R.layout.moment_content_list_item, parent, false);
            holder = new ViewHolder(convertView);
            convertView.setTag(holder);
        } else {
            holder = (ViewHolder) convertView.getTag();
        }

        MomentContentBean.DataBean bean = mList.get(position);
        holder.momentContentIvShow.setImageURI(Uri.parse(bean.getLitpic()));
        holder.momentContentTvTitle.setText(bean.getTitle());
        holder.momentContentTvTime.setText(bean.getPubdate());
        return convertView;
    }


    static class ViewHolder {
        @BindView(R.id.moment_content_ivShow)
        SimpleDraweeView momentContentIvShow;
        @BindView(R.id.moment_content_tvTitle)
        TextView momentContentTvTitle;
        @BindView(R.id.moment_content_tvTime)
        TextView momentContentTvTime;

        ViewHolder(View view) {
            ButterKnife.bind(this, view);
        }
    }
}
